from django.db import models

class UserInfo(models.Model):
    user_type_choices = (
        (1,'普通用户'),
        (2,'VIP'),
        (3,'SVIP'),
    )
    user_type = models.IntegerField(choices=user_type_choices)

    username = models.CharField(max_length=32,unique=True)
    password = models.CharField(max_length=64)
    roles = models.ManyToManyField("Role",blank=True)


class UserToken(models.Model):
    user = models.OneToOneField(to='UserInfo',on_delete=models.CASCADE)
    token = models.CharField(max_length=64)


class Role(models.Model):
    title = models.CharField(max_length=32)
    permissions = models.ManyToManyField('Permission',blank=True)

    def __str__(self):
        return self.title

class Permission(models.Model):
    authName = models.CharField(max_length=32,verbose_name='权限说明')
    url = models.CharField(max_length=128,verbose_name='含正则的url')

    def __str__(self):
        return self.authName